package com.example.demo.service;

import com.example.demo.mapper.UserMapper;
import com.example.demo.model.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Service
public class UserService {
    @Resource
    private UserMapper userMapper;

    public List<User> selectAll(){
        return userMapper.selectAll();
    }

    public void insertUser(){

        User user=new User();
        //id自增不用设置
        user.setUsername("老八");
        user.setPassword("123456");

        Date date=new Date();
        user.setCreateTime(date);
        user.setPhoto("000000");
        user.setState(1);

        Integer row= userMapper.insertUser(user);//默认情况下返回的是行数

    }

    public User selectUserById(Integer id){
        if(id<=0 || id ==null){
            System.out.println("参数有误");
        }

        return userMapper.selectUserById(id);
    }

    public void updateUserById(User user){

        int row =userMapper.updateUserById(user);
        System.out.println(row);
    }

    public void deleteUser(Integer id){
        if(id == null || id<=0){

            System.out.println("参数错误");
        }
        userMapper.deleteUser(id);
    }
}
